package com.persondemo.videoappliction.ui.vip.presenter;

import com.persondemo.videoappliction.bean.MeCollectBean;
import com.persondemo.videoappliction.net.BaseApi;
import com.persondemo.videoappliction.net.BaseObserver;
import com.persondemo.videoappliction.net.RxSchedulers;
import com.persondemo.videoappliction.ui.base.BasePresenter;
import com.persondemo.videoappliction.ui.vip.contract.CollectContract;

import javax.inject.Inject;

/**
 * Created by Administrator on 2018/4/20.
 */

public class CollectPresenter extends BasePresenter<CollectContract.View> implements CollectContract.Presenter {
    BaseApi baseApi;

    @Inject
    public CollectPresenter(BaseApi baseApi) {
        this.baseApi = baseApi;
    }

    @Override
    public void getdata(String device, String page) {
        baseApi.getcollect(device, page)
                .compose(RxSchedulers.applySchedulers())
                .compose(mView.bindToLife())
                .subscribe(new BaseObserver<MeCollectBean>() {
                    @Override
                    public void onSuccess(MeCollectBean meCollectBean) {
                        if (Integer.parseInt(page)>1){
                            mView.laodmore(meCollectBean);
                        }else {
                            mView.loaddata(meCollectBean);
                        }
                    }

                    @Override
                    public void onFail(Throwable e) {
                        mView.showFaild();
                    }
                });
    }
}
